package com.colorlight.cloud.mqtt.base.core.message.publish;

import com.colorlight.cloud.mqtt.base.api.message.PublishMessage;
import com.colorlight.cloud.mqtt.base.core.endpoint.MqttGateway;
import com.colorlight.cloud.mqtt.base.entity.IMqttHeaders;
import org.springframework.stereotype.Component;

/**
 * @author Demon
 * 指令下发
 */
@Component
public class Publish implements PublishMessage {
	private final MqttGateway gateway;
	
	public Publish(MqttGateway gateway) {
		this.gateway = gateway;
	}
	
	@Override
	public boolean publish(IMqttHeaders<?> iMqttHeaders) {
		byte[] message = (byte[]) iMqttHeaders.getMessage();
		gateway.sendToMqtt(iMqttHeaders.getTopic(), message);
		return true;
	}
}
